package com.bodystm.temperature.patient;

import java.util.Collections;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cascade;

import com.bodystm.temperature.bed.Bed;
import com.mimosa.common.entity.BaseEntity;
import com.mimosa.common.system.user.TUser;


/**
 * 鐥呬汉淇℃伅
 * 
 * @author ggeagle
 *
 */
@Table(name = "T_Patient")
@Entity
public class Patient extends BaseEntity {
	/**
	 * 搴婁綅淇℃伅鐨処D
	 */
	//private String bedId;
	/**
	 * 姓名
	 */
	private String name;
	/**
	 * 主治医师
	 */
	private String doctor;
	/**
	 * 值班护士
	 */
	private String nurse;
	/**
	 * 年龄
	 */
	private String age;
	/**
	 * 性别姓别
	 */
	private String sex;
	/**
	 * 设备号
	 */
	private String equipNo;
	/**
	 * 住院时间
	 */
	private Date startTime;
	
	private Date listenStartTime;
	private Date listenEndTime;
	private String disease;
	/*
	 * 病案号
	 */
	private String medicalRecordNumber;
	@Column(nullable=true)
	private Integer rangeStart;
	@Column(nullable=true)
	private Integer rangeEnd;
	//身份证号
	private String personnelId;
	//家庭住址
	private String address;
	// 
		@ManyToOne(cascade = { javax.persistence.CascadeType.REFRESH })
		private Bed bed;
////		// 科室
		@ManyToOne(cascade = { javax.persistence.CascadeType.REFRESH })
		private TUser user;
	public TUser getUser() {
			return user;
		}
//
		public void setUser(TUser user) {
			this.user = user;
		}
	// 部门id串
//		@Transient
//		private String userIds;
	// 人员
//		@SuppressWarnings("unchecked")
//		@OneToMany(mappedBy = "patient", orphanRemoval = true)
//		@Cascade(value = { org.hibernate.annotations.CascadeType.ALL })
//		private Set<PatientDepartment> userList = Collections.EMPTY_SET;
		
		@Transient
		private String bedIds;
	// 人员
		@SuppressWarnings("unchecked")
		@OneToMany(mappedBy = "patient", orphanRemoval = true)
		//@Cascade(value = { org.hibernate.annotations.CascadeType.ALL })
		private Set<PatientBedUser> bedUserList = Collections.EMPTY_SET;
                                                                      
	/*
	 *  就医类型（比如自费）
	 */
	private String medicalTreatmentType;
//	public Set<PatientDepartment> getUserList() {
//		return userList;
//	}
//
//	public void setUserList(Set<PatientDepartment> userList) {
//		this.userList = userList;
//	}

	/**
	 * 出院时间
	 */
	private Date endTime;
//	public String getUserIds() {
//		if (StringUtils.isBlank(userIds)) {
//			StringBuilder userIds = new StringBuilder();
//			for (PatientDepartment t : this.getUserList()) {
//				if (userIds.length() > 0) {
//					userIds.append(",");
//				}
//				userIds.append(t.gettUser().getId());
//			}
//			return userIds.toString();
//		} else {
//			return userIds;
//		}
//	}

	public Set<PatientBedUser> getBedList() {
		return bedUserList;
	}

	public void setBedList(Set<PatientBedUser> bedList) {
		this.bedUserList = bedList;
	}

//	public void setUserIds(String userIds) {
//		this.userIds = userIds;
//	}
	public String getBedIds() {
		if (StringUtils.isBlank(bedIds)) {
			StringBuilder bedIds = new StringBuilder();
			for (PatientBedUser t : this.getBedList()) {
				if (bedIds.length() > 0) {
					bedIds.append(",");
				}
				bedIds.append(t.getBed().getId());
			}
			return bedIds.toString();
		} else {
			return bedIds;
		}
	}

	public void setBedIds(String bedIds) {
		this.bedIds = bedIds;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getEquipNo() {
		return equipNo;
	}

	public void setEquipNo(String equipNo) {
		this.equipNo = equipNo;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

//	public String getBedId() {
//		return bedId;
//	}
//
//	public void setBedId(String bedId) {
//		this.bedId = bedId;
//	}

	public String getDoctor() {
		return doctor;
	}

	public void setDoctor(String doctor) {
		this.doctor = doctor;
	}

	public String getNurse() {
		return nurse;
	}

	public void setNurse(String nurse) {
		this.nurse = nurse;
	}

	public Date getListenStartTime() {
		return listenStartTime;
	}

	public void setListenStartTime(Date listenStartTime) {
		this.listenStartTime = listenStartTime;
	}

	public Date getListenEndTime() {
		return listenEndTime;
	}

	public void setListenEndTime(Date listenEndTime) {
		this.listenEndTime = listenEndTime;
	}

	public String getDisease() {
		return disease;
	}

	public void setDisease(String disease) {
		this.disease = disease;
	}

	public String getMedicalRecordNumber() {
		return medicalRecordNumber;
	}

	public void setMedicalRecordNumber(String medicalRecordNumber) {
		this.medicalRecordNumber = medicalRecordNumber;
	}

	public int getRangeStart() {
		return rangeStart;
	}

	public void setRangeStart(int rangeStart) {
		this.rangeStart = rangeStart;
	}

	public int getRangeEnd() {
		return rangeEnd;
	}

	public void setRangeEnd(int rangeEnd) {
		this.rangeEnd = rangeEnd;
	}

	public String getPersonnelId() {
		return personnelId;
	}

	public void setPersonnelId(String personnelId) {
		this.personnelId = personnelId;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getMedicalTreatmentType() {
		return medicalTreatmentType;
	}

	public void setMedicalTreatmentType(String medicalTreatmentType) {
		this.medicalTreatmentType = medicalTreatmentType;
	}

	public Bed getBed() {
		return bed;
	}

	public void setBed(Bed bed) {
		this.bed = bed;
	}
}